package com.situ.tos2024.util;

public class JsonResult {
    private boolean success = true;//后台是否执行成功
    private int code = 0;//状态码
    private String msg = "";//消息
    private long count = 0;//返回数据的数量
    private Object data;//数据

    public JsonResult(boolean success, int code) {
        this.success = success;
        this.code = code;
    }

    public JsonResult(boolean success, int code, String msg) {
        this(success, code);
        this.msg = msg;
    }

    public JsonResult(boolean success, int code, String msg, long count, Object data) {
        this(success, code, msg);
        this.count = count;
        this.data = data;
    }

    public static JsonResult success(long count, Object data) {
        return success(0, "", count, data);
    }

    public static JsonResult success(int code, String msg, long count, Object data) {
        return new JsonResult(true, code, msg, count, data);
    }

    public static JsonResult success(int code, String msg) {
        return new JsonResult(true, code, msg);
    }

    public static JsonResult success(int code) {
        return success(code, "");
    }

    public static JsonResult success() {
        return success(0);
    }

    public static JsonResult failure(int code, String msg) {
        return new JsonResult(false, code, msg);
    }

    public static JsonResult failure(String msg) {
        return failure(msg);
    }

    public boolean isSuccess() {
        return success;
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public long getCount() {
        return count;
    }

    public Object getData() {
        return data;
    }
}
